package com.dpfmanage.api.project.dpfmanage.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;


/**
 * 删除标识枚举
 */
@AllArgsConstructor
@Getter
public enum DelFlagEnum {
    NOT_DEL(0, "正常"),
    DEL(2, "已删除"),
    ;

    private Integer code;
    private String name;

    /**
     * 通过name获取code
     *
     * @param name
     * @return
     */
    public static Integer getCodeByName(String name) {
        DelFlagEnum[] types = values();
        for (DelFlagEnum type : types) {
            if (Objects.equals(type.name, name)) {
                return type.code;
            }
        }
        return null;
    }

    /**
     * 通过code获取name
     *
     * @param code
     * @return
     */
    public static String getNameByCode(String code) {
        DelFlagEnum[] types = values();
        if (code != null) {
            for (DelFlagEnum type : types) {
                if (type.code.equals(code)) {
                    return type.name;
                }
            }
        }
        return "";
    }

}
